//
//  EPMVisitorView.m
//  WeiBoByOC
//
//  Created by 马继鵬 on 17/3/20.
//  Copyright © 2017年 7TH. All rights reserved.
//

#import "EPMVisitorView.h"

@interface EPMVisitorView()
    @property (weak,nonatomic) UIImageView* cycleView;
    @property (weak,nonatomic) UIImageView* bigHomeView;
    @property (weak,nonatomic) UIImageView* coverView;
    @property (weak,nonatomic) UILabel* descLabel;
    @property (weak,nonatomic) UIButton* logBtn;
    @property (weak,nonatomic) UIButton* registBtn;
    
@end
@implementation EPMVisitorView

- (instancetype)initWithFrame:(CGRect)frame
    {
        if(self = [super initWithFrame:frame])
        {
           [ self setupUI ];
        }
        return self ;
    }
    
    
#pragma
#pragma-更新视图
    - (void)upDateTitle:(NSString *)title imageName:(NSString *)imageName isHome:(BOOL)isHome
    {
        self.bigHomeView.hidden = !isHome;
        self.coverView.hidden = !isHome;
        self.cycleView.image = [UIImage imageNamed:imageName];
        self.descLabel.text = title;
        if (isHome){
            
            [self startAnimation];
        }
    }
#pragma
#pragma-添加动画
    - (void)startAnimation{
        CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
        animation.duration = 15;
        animation.fromValue = 0;
        animation.toValue = [NSNumber numberWithFloat:2*M_PI];
        animation.repeatCount = MAXFLOAT;
        animation.removedOnCompletion = NO;
        [self.cycleView.layer addAnimation:animation forKey:nil];
    }
    
#pragma
#pragma-设置UI
    - (void)setupUI{
        
        self.backgroundColor = [UIColor colorWithWhite:237.0/255.0 alpha:1.0];
        //添加环形视图
        UIImageView* cycleView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_smallicon"]];
       [self addSubview:cycleView];
        _cycleView = cycleView;
        [cycleView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.offset(0);
            make.centerY.offset(-70);
        }];
        [cycleView sizeToFit];
        //添加遮罩
        UIImageView* coverView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_mask_smallicon"]];
        [self addSubview:coverView];
        _coverView = coverView;
        [coverView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(cycleView);
        }];
        [coverView sizeToFit];
        
        //添加房子
        UIImageView* bigHomeView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_house"]];
        [self addSubview:bigHomeView];
        _bigHomeView = bigHomeView;
        [bigHomeView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(cycleView);
        }];
        [bigHomeView sizeToFit];
        
        //添加描述标签
        UILabel* desLabel = [UILabel EPM_Title:@"1234567" textColor:[UIColor darkGrayColor] fontSize:14];
        [self addSubview:desLabel];
        _descLabel = desLabel;
        [desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(cycleView);
            make.top.equalTo(cycleView.mas_bottom).offset(17);
        }];
        desLabel.preferredMaxLayoutWidth = 220;
        
        //添加按钮
        UIButton* loadBtn = [UIButton EPM_title:@"登录" imageName:nil backImage:@"common_button_white"];
        [loadBtn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        [self addSubview:loadBtn];
        _logBtn = loadBtn;
        [loadBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.trailing.equalTo(self.mas_centerX).offset(-7);
            make.top.equalTo(desLabel.mas_bottom).offset(17);
            make.width.mas_equalTo(100);
        }];
       [ loadBtn addTarget:self action:@selector(userLoadbtnClick:) forControlEvents:UIControlEventTouchUpInside];
        
        UIButton* registBtn = [UIButton EPM_title:@"注册" imageName:nil backImage:@"common_button_white"];
        [registBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        [self addSubview:registBtn];
        _registBtn = registBtn;
        
        [registBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.mas_centerX).offset(7);
            make.centerY.equalTo(loadBtn);
            make.width.mas_equalTo(100);
        }];
        [registBtn addTarget:self action:@selector(userRegisterBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    
    
#pragma
#pragma-添加点击事件
    - (void)userLoadbtnClick:(UIButton*)sender
    {
        if(_loadBtnBlock)
        {
            _loadBtnBlock(self);
        }
    }
    
    - (void)userRegisterBtnClick:(UIButton*)sender
    {
        if (_registerBtnBlock)
        {
            _registerBtnBlock(self);
        }
    }
    
@end
